package comits.web.client.servlets.demo;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import comits.business.tiers.rp.tasks.ws.ControleurOrdreSortie;

public class ConsulterOrdreSortieServlet extends HttpServlet{
	
	/**
	 * 
	 * @author Ludmilla
	 */
	private static final long serialVersionUID = 7526928611471348888L;

	protected void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
	
	
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String action = request.getParameter("action");
		HttpSession session = request.getSession();  
		
		if(action.equals("Valider")){		
			ControleurOrdreSortie ordsortie = new ControleurOrdreSortie();
			int cptEmp = (Integer)session.getAttribute("nbEmp");	
			Integer numEmp,numCmd;
			String delimiter = "-";
			String infos,nomVar;
			
			for(int i = 1 ; i<cptEmp; i++){
				 nomVar = "employe"+i;
				 infos = request.getParameter(nomVar);	
				 try{
				 String str[]=infos.split(delimiter);
				 numEmp = Integer.valueOf(str[0]);
				 numCmd = Integer.valueOf(str[1]);
				 if(numEmp!=0 && numCmd!=0) ordsortie.affecterBonSortie(numEmp,numCmd);
				 
				 }catch( NullPointerException e){
					 getServletContext().getRequestDispatcher("/consulterOrdreSortie.jsp").forward(request, response);	
				 }	
			}					
			getServletContext().getRequestDispatcher("/consulterOrdreSortie.jsp").forward(request, response);	
		}
	}
	
	/**
	 * Returns a short description of the servlet.
	 * 
	 * @return a String containing servlet description
	 */
	public String getServletInfo() {
		return "Short description";
	}// </editor-fold>
	
}
